﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using playwrightJu3.Core;
using Windows.UI.Popups;

namespace playwrightJu3.Windows
{
    /// <summary>
    /// NewProjDialog.xaml 的交互逻辑
    /// </summary>
    public partial class NewProjDialog : Window
    {
        public NewProjDialog()
        {
            InitializeComponent();
            projTitleTextBox.Focus();
        }
        private string GetStringFromResources(string key)
        {
            return Properties.Resources.ResourceManager.GetString(key) ?? key;
        }
        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }

        private void CreateButton_Click(object sender, RoutedEventArgs e)
        {

            if (!Checkers.IsValidFileName(projTitleTextBox.Text))
            {
                InfoDialog infoDialog = new InfoDialog(GetStringFromResources("InvalidProjectName"), GetStringFromResources("InvalidProjectNameDescription"));
                infoDialog.ShowDialog();
                return;
            }
            if (!Checkers.IsFolderExists(projLocationTextBox.Text))
            {
                InfoDialog infoDialog = new InfoDialog(GetStringFromResources("FolderNotExists"), GetStringFromResources("FolderNotExistsDescription"));
                infoDialog.ShowDialog();
                return;
            }
            else
            {
                Project project = new Project()
                {
                    Location = projLocationTextBox.Text,
                    Title = projTitleTextBox.Text
                };
                project.Create();
            }
            DialogResult = true;
            Close();
        }

        private void Browse_Click(object sender, RoutedEventArgs e)
        {
            OpenFolderDialog dialog = new OpenFolderDialog()
            {
                Multiselect = false,
                Title = GetStringFromResources("SelectAFolderForYourProject"),
            };
            if (dialog.ShowDialog() == true)
            {
                projLocationTextBox.Text = dialog.FolderName;
            }
        }


    }
}
